﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace MVCSpike
{
    class CatControl : MvcControlBase<CatModel, ICatView>
    {
        public CatControl(CatModel model, ICatView view)
        {
            Initialize(model, view);
        }

        protected override void DoAfterWireEvents()
        {
            View.RegisterChangRequestListener<String>("Name", View_OnNameChangeRequest);
            View.RegisterChangRequestListener<Int32>("Age", View_OnAgeChangeRequest);    
        }

        private void View_OnAgeChangeRequest(object sender, PropertyChangeRequestEventArgs<int> e)
        {
            Model.Age = e.RequestedValue;
        }

        private void View_OnNameChangeRequest(object sender, PropertyChangeRequestEventArgs<string> e)
        {
            Model.Name = e.RequestedValue;
        }

        protected override void UnwireEvents()
        {
            Model.PropertyChanged -= Model_PropertyChanged;
            View.UnRegisterChangRequestListener<String>("Name", View_OnNameChangeRequest);
            View.UnRegisterChangRequestListener<Int32>("Age", View_OnAgeChangeRequest);
        }

    }
}
